package cn.the.angry.util;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import org.jbox2d.common.Color3f;
import org.jbox2d.common.OBBViewportTransform;
import org.jbox2d.common.Vec2;
import org.jbox2d.common.XForm;
import org.jbox2d.dynamics.DebugDraw;

import cn.the.angry.tests.TestUtils;

public class DrawUtil extends DebugDraw
{
	private final OBBViewportTransform transform;
	private final BufferedImage displayBufferImage;
	
	public DrawUtil(final BufferedImage displayBufferImage)
	{
		super(new OBBViewportTransform());
		this.transform=(OBBViewportTransform) super.getViewportTranform();
		this.displayBufferImage=displayBufferImage;
	}
	
	public BufferedImage getDisplayBufferImage()
	{
		return displayBufferImage;
	}

	@Override
	public void drawCircle(final Vec2 argCenter, final float radius, final Color3f color)
	{
		//System.out.println("drawCircle");
//		BufferedImage buffer=new BufferedImage((int) radius*2, (int) radius*2, BufferedImage.TYPE_INT_ARGB);
//		Graphics2D g2d=buffer.createGraphics();
//		g2d.setColor(new Color((int) color.x, (int) color.y, (int) color.z));
//		g2d.drawOval(0, 0, (int) radius*2, (int) radius*2);
//		buffer=TestUtils.rotateImage(buffer, (int) radius*2, (int) radius*2, (int) radius);
//		displayBufferImage.createGraphics().drawImage(buffer, (int)(argCenter.x-radius), (int)(argCenter.y-radius), (int) radius*2, (int) radius*2, null);
//		g2d.dispose();
	}
	@Override
	public void drawPoint(Vec2 arg0, float arg1, Color3f arg2)
	{
		//System.out.println("drawCircle");		
	}
	@Override
	public void drawSegment(Vec2 arg0, Vec2 arg1, Color3f arg2)
	{
		//System.out.println("drawSegment");		
	}
	@Override
	public void drawSolidCircle(Vec2 arg0, float arg1, Vec2 arg2, Color3f arg3)
	{
		//System.out.println("drawSolidCircle");		
	}
	@Override
	public void drawSolidPolygon(Vec2[] arg0, int arg1, Color3f arg2)
	{
		//System.out.println("drawSolidPolygon");		
	}
	@Override
	public void drawString(float arg0, float arg1, String arg2, Color3f arg3)
	{
		//System.out.println("drawString");		
	}

	@Override
	public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color)
	{
		//System.out.println("drawPolygon");
//		final Graphics2D g2d=displayBufferImage.createGraphics();
//		g2d.setColor(new Color((int) color.x, (int) color.y, (int) color.z));
//		int i=1;
//		Vec2 v1=new Vec2(),v2=new Vec2();
//		for(;i<vertexCount;++i)
//		{
//			transform.getWorldToScreen(vertices[i-1], v1);
//			transform.getWorldToScreen(vertices[i], v2);
//			g2d.drawLine((int) v1.x, (int) v1.y, (int) v2.x, (int) v2.y);
//		}
//		transform.getWorldToScreen(vertices[i-1], v1);
//		transform.getWorldToScreen(vertices[0], v2);
//		g2d.drawLine((int) v1.x, (int) v1.y, (int) v2.x, (int) v2.y);
//		
//		g2d.dispose();
	}

	@Override
	public void drawXForm(XForm xf)
	{
		//System.out.println("drawXForm");		
	}

}
